package fy.hr.constant;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import fy.hr.controller.WorkTimeConfController;
import fy.util.MyUtil;

public class OA2HRConstant {

	public static final String[] START_WORK_TIME = { "07:30:00", "13:30:00" };

	public static final String[] END_WORK_TIME = { "11:30:00", "17:30:00" };

/*private static final String[] _8AM_CORP = { "1021", "1009", "1011", "1010",
			"1023", "1012", "1006","1027" };// 8点上班的制造部的PKCORP
*/
	public static final String[] AWAYTYPEARRAY = { "0001K71000000000020O",
			"1002N310000000000A29", "1002N310000000000A2A",
			// 国外出差
			"1002N310000000000A2B" };
	
	private static Map<String, String[]> workTimeMap = new HashMap<String, String[]>();

	public static String LOGFILEPATH;
	
	public static void setWorkTime(String[] workTime,String accountID){
		workTimeMap.put(accountID, workTime);
	}

	public static String getWorkTime(String time, String pk_corp,String accountID) throws IOException {
//		System.err.println(pk_corp+"//"+accountID);
		String[] workTime = workTimeMap.get(accountID);
//		System.err.println("工作时间"+workTime);
		if(workTime==null){
			 	String filePath = MyUtil.getRealPath(WorkTimeConfController.class) +"../workTimeConf" +accountID;
            	 File file = new File(filePath);
            	 if(file.exists()&&file.isFile()){
            	 FileInputStream fis = new FileInputStream(filePath);
	             InputStreamReader isr = new InputStreamReader(fis, "utf-8");
	             BufferedReader br = new BufferedReader(isr);
	             String zaoshangshangbanshijian = br.readLine();
//	             System.err.println("早上时间"+zaoshangshangbanshijian);
	             if(zaoshangshangbanshijian != null && !"".equals(zaoshangshangbanshijian))
	             {
	                 String zaoshangxiabanshijian = br.readLine();
	                 String xiawushangbanshijian = br.readLine();
	                 String xiawuxiabanshijian = br.readLine();
//	                 System.err.println(zaoshangxiabanshijian+"||"+xiawushangbanshijian+"||"+xiawuxiabanshijian);
	                 br.close();
	               
	                 
	                 workTime = new String[]{ zaoshangshangbanshijian, zaoshangxiabanshijian,xiawushangbanshijian,xiawuxiabanshijian};
	                
	                 workTimeMap.put(accountID, workTime);
	             }
            	 
             }else{
            	 workTime = new String[]{ "07:30:00", "11:30:00", "13:00:00","17:00:00"};
             }
		}			
//		System.err.println("下午："+END_WORK_TIME[1].equals(time));
//		System.err.println("下午："+END_WORK_TIME[1]);
//		System.err.println("2:"+time);
		
			return START_WORK_TIME[0].equals(time) ? workTime[0]
					: (START_WORK_TIME[1].equals(time) ? workTime[2]
							: (END_WORK_TIME[0].equals(time) ? workTime[1]
									: (END_WORK_TIME[1].equals(time) ? workTime[3]
											: "")));

//		if ("1015".equals(pk_corp)) {
//			return START_WORK_TIME[0].equals(time) ? "07:30:00"
//					: (START_WORK_TIME[1].equals(time) ? "12:50:00"
//							: (END_WORK_TIME[0].equals(time) ? "11:20:00"
//									: (END_WORK_TIME[1].equals(time) ? "17:00:00"
//											: "")));
//		}
//
//		boolean same = false;
//		for (int i = 0, length = _8AM_CORP.length; i < length; i++) {
//			if (_8AM_CORP[i].equals(pk_corp)) {
//				same = true;
//				break;
//			}
//		}
//请假
//		return same ? (START_WORK_TIME[0].equals(time) ? "08:00:00"
//				: (START_WORK_TIME[1].equals(time) ? "13:30:00"
//						: (END_WORK_TIME[0].equals(time) ? "12:00:00"
//								: (END_WORK_TIME[1].equals(time) ? "17:30:00"
//										: "")))) : time;
	}

	// public static String[] LEAVETEMPLATECODES = { "leave01", "leave02",
	// "leave03", "leave04", "leave05", "leave06", "leave07", "leave08",
	// "leave09", "leave10", "leave11" };

}
